
import { ConfigProvider } from 'antd';
import ReactDOMClient from 'react-dom/client'
import { themeConfig } from "@/constant";
import zhCN from 'antd/locale/zh_CN';

/** 挂在组件到跟上 */
export function mounting(node: JSX.Element, id = 'UI-HF-INVOICE-PLATFORM-VITE-REACT-ANTD') {

    ReactDOMClient.hydrateRoot(
        getContainer(), (
        <ConfigProvider theme={themeConfig} locale={zhCN} >
            {node}
        </ConfigProvider>
    ))

    function getContainer() {
        return document.querySelector(`#${id}`) || createElement();
    }

    function createElement() {
        const div = document.createElement("div")
        div.id = id;
        document.body.appendChild(div);
        return div;
    }
}
